import request from "@/utils/request";

/**
 * 读取角色列表
 */
export function read() {
  return request({
    url: "/api/role",
    method: "get"
  });
}

/**
 * 获取系统角色的详细信息
 * @param {角色id} id
 */
export function load(id) {
  return request({
    url: "/api/role/" + id,
    method: "get"
  });
}

/**
 * 更新系统角色
 * @param {新角色模型} param
 */
export function update(param) {
  return request({
    url: "/api/role",
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" }
  });
}

/**
 * 删除系统角色
 * @param {角色 id} id
 */
export function destroy(id) {
  return request({
    url: "/api/role/" + id,
    method: "delete",
    headers: { "Content-Type": "application/json" }
  });
}

/**
 * 获取角色的菜单权限
 * @param {角色id} param
 */
export function permission(id) {
  return request({
    url: "/api/role/" + id + "/menu",
    method: "get"
  });
}

/**
 * 保存权限
 * @param {选中数组} param
 */
export function save(id, param) {
  return request({
    url: "/api/role/" + id + "/menu",
    method: "post",
    data: param,
    headers: { "Content-Type": "application/json" }
  });
}
